Skip to content

Bugfix/static function #739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 19, 2017
Merged

Conversation

NlightNFotis
Copy link
Contributor

Greetings,

This pull request contains a fix for the issue reported in pr #718. This contains the fix, changes for the tests so that they are now active, along with two more tests that show that goto-cc now correctly reports ambiguity that arises due to usage of the qualifier static between two functions with the same name and signature but in two different translation units.

Paging @martin-cs to add some concerns he has and @tautschnig for reviewing the solution.

// We also don't allow for the _start function to have any of its
// function calls to be inlined
if(!goto_function.body_available() ||
f_it->first==ID__start)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use ID__start directly, use goto_functions.entry_point() instead.

@@ -149,7 +150,7 @@ void remove_internal_symbols(
else if(is_function)
{
// body? not local (i.e., "static")?
if(has_body && !is_file_local)
if(has_body || (!is_file_local && (config.main == symbol.name.c_str())))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That logic appears wrong to me - shouldn't this code be:

if(has_body &&
   (!is_file_local || config.main==symbol.name))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - & since this wasn't picked up by the tests I suggest adding an additional test that verifies an unused static function with body is correctly removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, after discussing it with @thk123 it appears that I had understood the initial condition wrong, and thought that we should include a function "if it has a body or ...". Thomas let me know that this is wrong, and that if it has no body it's useless to us, so you're right. It will be updated accordingly.

@NlightNFotis NlightNFotis force-pushed the bugfix/static_function branch from 5b996c0 to 1a657b5 Compare March 31, 2017 10:38
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the test would fail under the old logic.

@@ -0,0 +1 @@
static int foo(int a);
Copy link
Contributor

@thk123 thk123 Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symbol would still be included with the old logic since it is both static and without body. The function should have a body and should still be excluded.

@NlightNFotis NlightNFotis force-pushed the bugfix/static_function branch from df86a4c to dbcff69 Compare March 31, 2017 11:25
@tautschnig
Copy link
Collaborator

@kroening Still left to decide whether this behaviour is actually desirable, i.e., whether functions marked "static" constitute valid entry points at all.

@thk123
Copy link
Contributor

thk123 commented Mar 31, 2017

@tautschnig Reason for needing this is for generating the test suite for a static function is useful when trying to generate unit tests.

@peterschrammel
Copy link
Member

@thk123, how do you run these tests?

@NlightNFotis
Copy link
Contributor Author

NlightNFotis commented Mar 31, 2017

@peterschrammel We talked with thk123 about it, and the simple solution is to include the .c file in the test (as we already do) if the function is static.

@@ -149,7 +150,8 @@ void remove_internal_symbols(
else if(is_function)
{
// body? not local (i.e., "static")?
if(has_body && !is_file_local)
if(has_body &&
(!is_file_local || (config.main==symbol.name.c_str())))
get_symbols_rec(ns, symbol, exported);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the .c_str() doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kroening It's returning a const char * that we can compare to the std::string that is config.main. Without it, we get the following error message:

remove_internal_symbols.cpp: In function 'void remove_internal_symbols(symbol_tablet&)':
remove_internal_symbols.cpp:153:54: error: no match for 'operator==' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'const irep_idt {aka const dstringt}')
       if(has_body || (!is_file_local && (config.main == symbol.name)))

If we need to change it, I can change the c_str() call to as_string(), but they appear to do exactly the same thing, with the difference that c_str() returns a C string whereas as_string() returns a c++ string.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kroening @NlightNFotis I'm wondering why config.main is a string. I can't see a good reason for it not to be an irep_idt.

@martin-cs
Copy link
Collaborator

martin-cs commented Apr 3, 2017 via email

@kroening
Copy link
Member

kroening commented Apr 4, 2017

Sorry, don't see why inlining into the _start function is a problem?

@thk123
Copy link
Contributor

thk123 commented Apr 4, 2017

@kroening Unfortunately the original PR for this change has been lost - but from memory and based off the commit message, the problem was to do with the interpreter not recording entering and exiting a function as it never entered the function. This commit is in test-gen-support so perhaps it shouldn't be back ported to CBMC?

thk123 and others added 4 commits April 18, 2017 11:17
When the partial inlining comes to the _Start function, it skips over
it. We don't want inlining on the start function because if we are
trying to find the entry point for the users code, it is important it
hasn't been inlined into GOTO generated code.
…elected as the entry point and changed the tests to CORE rather than KNOWNBUG
…n error when a symbol ambiguity due to static arises.
@NlightNFotis NlightNFotis force-pushed the bugfix/static_function branch from dbcff69 to 62995f5 Compare April 18, 2017 10:25
@kroening kroening merged commit 94e833d into diffblue:master Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants